package com.comment.pojo.domain.logic.core;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Getter
@Setter
public class Target {
    @ApiModelProperty("领取时数据")
    private Long whenReceiving;
    @ApiModelProperty("需要值")
    private Long needValue;
    @ApiModelProperty("目标值")
    private Long targetValue;
    @ApiModelProperty("已获得值")
    private Long hasValue;

    public Target(Long whenReceiving, Long needValue) {
        this.whenReceiving = whenReceiving;
        this.needValue = needValue;
        this.targetValue = whenReceiving + needValue;
        this.hasValue = whenReceiving;
    }

    public boolean isComplete() {
        return hasValue >= targetValue;
    }

    public void flush(Long hasValue, Long needValue) {
        this.hasValue = hasValue;
        if (needValue != null) {
            this.needValue = needValue;
            this.targetValue = whenReceiving + needValue;
        }
    }
}
